﻿
app.controller('headerCtrl', ['$scope', function($scope) {

	$scope.userName = $.cookie('userName');
	if($.trim($.cookie('userName')) != "") {
		$("#not-login").hide();
	}
	try {
		$scope.User = $.parseJSON($.cookie('User'));
		$scope.address = $.parseJSON($.parseJSON($.cookie('User')).address);
	} catch(e) {
		console.log("已知异常："+e);
	}
	
}]);

app.directive('header', function () {
    return {
        restrict: 'E',
        templateUrl: 'directives/head/header.html',
        replace: true,
        link: function (scope, elements, attrs) {
            /* 头部下拉 */
            $("ul.ui-rt > li").hover(function(){
                $(this).find(".down-con").stop().slideDown(200);
            },function(){
                $(this).find(".down-con").stop().slideUp(200);
            });
        }
    };
});

app.directive('logo', function() {
    return {
        restrict: 'E',
        templateUrl: 'directives/head/logo.html',
        replace: true,
        link: function (scope, elements, attrs) {
            /* 首页轮播 */
            jQuery(".slideBox").slide({
                mainCell: ".bd ul",
                effect: "left",
                delayTime: 600,	//滚动持续600毫秒
                interTime: 5000,	//滚动延迟时间，单位：毫秒
                autoPlay: true,
                easing: "swing",
            });
        }
    };
});

app.directive('nav', function() {
    return {
        restrict: 'E',
        templateUrl: 'directives/head/nav.html',
        replace: true,
        link: function (scope, elements, attrs) {
            scope.title = attrs.title;
            scope.isTaskCenter = attrs.isTaskCenter;
        }
    };
});


/* 鼠标移动到页头用户名上 */
function overUserName(dom) {
	$(dom).find(".user-down-con").stop().slideDown(200);
}
function outUserName(dom) {
	$(dom).find(".user-down-con").stop().slideUp(200);
}

/** 用户注销登录 */
function userExit() {
	AQ.callAQ("userExit.do", null, function(result) {
		location.replace("login.html");
	}, function(err, code){
		Utils.msgDialog(err + "["+ code +"]");
	});
}

/* 查看余额 */
function lookBalance(dom) {
	AQ.callAQ("refreshUserInfo.do", null, function(result) {
		var User = result[1];
		$(dom).siblings(".down-con").find("#money a").text("余额：" + User.money);
		$(dom).siblings(".down-con").find("#feibi a").text("飞币：" + User.feibi);
		$.cookie("userName", User.userName, {expires: 30});
		$.cookie("User", JSON.stringify(User));
	}, function(err, code){
		console.log(err + "["+ code +"]");
	});
}
